package com.example.point2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView AScoreText, BScoreText;
    private Button AAddThreeBtn, AAddTwoBtn, AAddOneBtn;
    private Button BAddThreeBtn, BAddTwoBtn, BAddOneBtn;
    private Button ResetBtn;
    private int AScore, BScore;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        AScoreText = findViewById(R.id.aScoreText);
        BScoreText = findViewById(R.id.bScoreText);
        AAddThreeBtn =findViewById(R.id.aAddThreeBtn);
        AAddTwoBtn = findViewById(R.id.aAddTwoBtn);
        AAddOneBtn = findViewById(R.id.aAddOneBtn);
        BAddThreeBtn = findViewById(R.id.bAddThreeBtn);
        BAddTwoBtn = findViewById(R.id.bAddTwoBtn);
        BAddOneBtn = findViewById(R.id.bAddOneBtn);
        ResetBtn =  findViewById(R.id.resetBtn);

        AAddThreeBtn.setOnClickListener(this);
        AAddTwoBtn.setOnClickListener(this);
        AAddOneBtn.setOnClickListener(this);
        BAddThreeBtn.setOnClickListener(this);
        BAddTwoBtn.setOnClickListener(this);
        BAddOneBtn.setOnClickListener(this);
        ResetBtn.setOnClickListener(this);
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aAddThreeBtn:
                aAddScore(3);
                break;
            case R.id.aAddTwoBtn:
                aAddScore(2);
                break;
            case R.id.aAddOneBtn:
                aAddScore(1);
                break;
            case R.id.bAddThreeBtn:
                bAddScore(3);
                break;
            case R.id.bAddTwoBtn:
                bAddScore(2);
                break;
            case R.id.bAddOneBtn:
                bAddScore(1);
                break;
            case R.id.resetBtn:
                rs();
                break;
        }
    }

    private void aAddScore(int score) {
        AScore = AScore + score;
        displayAScore(AScore);
    }

    private void bAddScore(int score) {
        BScore = BScore + score;
        displayBScore(BScore);
    }

    private void rs(){
        AScore=0;
        BScore=0;
        displayAScore(AScore);
        displayBScore(BScore);
    }

    private void resetScore() {
        AScore = 0;
        BScore = 0;
        displayAScore(AScore);
        displayBScore(BScore);
    }

    private void displayAScore(int score) {
        AScoreText.setText(String.valueOf(score));
    }


    private void displayBScore(int score) {
        BScoreText.setText(String.valueOf(score));
    }
}